package br.com.app;

import glaf.GButton;
import glaf.GDialog;
import glaf.GLabel;
import glaf.GTextField;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

import utils.GColor;
import utils.GIcon;

@SuppressWarnings("serial")
public class AppDialog extends GDialog {

	private GButton btExit;
	private GButton btSave;

	private String id;
	private GTextField tfQuando;
	private GTextField tfOnde;
	private GTextField tfOque;
	private GTextField tfComQuem;

	public AppDialog() {
		this(null);
	}

	public AppDialog(Frame owner) {
		super(owner);
		initUI();
	}

	private void initUI() {
		setSize(300, 300);

		GLabel lbNorth = new GLabel("Adicionar");
		lbNorth.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0));

		tfQuando = new GTextField();
		tfOnde = new GTextField();
		tfOnde.setForeground(GColor.BLUE900);
		tfOque = new GTextField();
		tfComQuem = new GTextField();

		JPanel pnCenter = new JPanel();
		pnCenter.setLayout(new BoxLayout(pnCenter, BoxLayout.Y_AXIS));
		pnCenter.setBackground(GColor.BLUE700);
		pnCenter.setBorder(BorderFactory.createEmptyBorder(25, 25, 10, 25));
		pnCenter.add(new GLabel("Quando?", 16));
		pnCenter.add(tfQuando);
		pnCenter.add(Box.createRigidArea(new Dimension(0, 5)));
		pnCenter.add(new GLabel("Onde?", 16));
		pnCenter.add(tfOnde);
		pnCenter.add(Box.createRigidArea(new Dimension(0, 5)));
		pnCenter.add(new GLabel("O que?", 16));
		pnCenter.add(tfOque);
		pnCenter.add(Box.createRigidArea(new Dimension(0, 5)));
		pnCenter.add(new GLabel("Com quem?", 16));
		pnCenter.add(tfComQuem);

		JPanel pnSouth = new JPanel();
		pnSouth.setLayout(new GridLayout(1, 2));
		pnSouth.setBackground(GColor.BLUE700);
		pnSouth.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
		btExit = new GButton(GIcon.BT_BACK48);
		btSave = new GButton(GIcon.BT_FORWARD48);
		pnSouth.add(btExit);
		pnSouth.add(btSave);

		add(pnCenter, BorderLayout.CENTER);
		add(pnSouth, BorderLayout.SOUTH);
	}

	public void setVisible(Coisa c, boolean b) {
		id = c.getId();
		tfQuando.setText(c.getQuando());
		tfOnde.setText(c.getOnde());
		tfOque.setText(c.getoQue());
		tfComQuem.setText(c.getComQuem());
		if (tfQuando.getText().equals("-")) {
			tfQuando.setText("");
		}
		if (tfOnde.getText().equals("-")) {
			tfOnde.setText("");
		}
		if (tfOque.getText().equals("-")) {
			tfOque.setText("");
		}
		if (tfComQuem.getText().equals("-")) {
			tfComQuem.setText("");
		}
		super.setVisible(b);
	}

	public String getId() {
		return id;
	}

	public void setId(String text) {
		id = text;
	}

	public GTextField getTfQuando() {
		return tfQuando;
	}

	public GTextField getTfOnde() {
		return tfOnde;
	}

	public GTextField getTfOque() {
		return tfOque;
	}

	public GTextField getTfComQuem() {
		return tfComQuem;
	}

	public GButton getBtExit() {
		return btExit;
	}

	public GButton getBtSave() {
		return btSave;
	}

}